from time import ctime
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException


driver = webdriver.Firefox()

# 隐式等待
driver.implicitly_wait(10)
"""
隐式等待不影响其脚本的运行速度,当要找的元素已经找到时,则继续运行
找不到则在整个页面轮询,如果10秒内没有轮询到就抛出异常
"""
driver.get('https://www.baidu.com')
driver.maximize_window()

try:
    print(ctime)
    driver.find_element_by_id('kw').send_keys('selenium')
except NoSuchElementException as e:
    print(e)
finally:
    print(ctime())
    driver.quit()

